<script>
	import jssdk from "weixin-js-sdk";
	import util from "./utils/util.js"
	import siteinfo from "./siteinfo.js"
	export default {
		data() {
			return {};
		},
		onLaunch: function() {
			this.globalData.siteroot = siteinfo.host + '/web.php';
			const system = uni.getSystemInfoSync().system.toLowerCase();
			if (system.indexOf('android') > -1) {
				this.globalData.system = 'android';
			} else if (system.indexOf('ios') > -1) {
				this.globalData.system = 'ios';
			} else if (system.indexOf('macos') > -1) {
				this.globalData.system = 'macos';
			} else if (system.indexOf('windows') > -1) {
				this.globalData.system = 'windows';
			} else {
				this.globalData.system = 'other';
			}
			if (system.safeArea) {
				const safeAreaHeight = system.screenHeight - system.safeArea.bottom;
				this.globalData.safeAreaHeight = parseInt(safeAreaHeight * 750 / system.screenWidth)
			}
			// uni.hideTabBar()

			// 站点sitecode
			var search = window.location.search
			if(search && search.indexOf('?') != -1) {
				var sitecode = '';
				if(search.length == 5) {
					sitecode = search.substr(1, 4)
				} else if (search.length > 5) {
					var char = search.charAt(5)
					if(char == '&' || char == '#' || char == '=' || char == '/') {
						sitecode = search.substr(1, 4)
					}
				}
				if (sitecode) {
					uni.setStorageSync('sitecode', sitecode)
				}
			}

			// 初始化微信jssdk
			util.request({
					url: '/h5/getShareInfo',
					data: {
						url: window.location.href
					}
				})
				.then((res) => {
					const jssdkConfig = res.data.jssdk_config;
					const share_title = res.data.share_title;
					const share_link = res.data.share_link;
					const share_desc = res.data.share_desc;
					const share_image = res.data.share_image;

					if (jssdkConfig) {
						jssdk.config(jssdkConfig);
						jssdk.ready(function() {
							jssdk.updateAppMessageShareData({
								title: share_title,
								desc: share_desc,
								link: share_link,
								imgUrl: share_image,
								success: function() {
									// 设置成功
								}
							})
							jssdk.updateTimelineShareData({
								title: share_title,
								link: share_link,
								imgUrl: share_image,
								success: function() {
									// 设置成功
								}
							})
						});
					}

					this.globalData.jssdk = jssdk
				});
		},
		globalData: {
			siteroot: '',
			system: '',
			safeAreaHeight: 0,
			util: util,
			jssdk: null,
			setting: null
		}
	};
</script>
<style>
	page {
	    box-sizing: border-box;
	    /*兼容 IOS<11.2*/
	    padding-bottom: constant(safe-area-inset-bottom);
	    /*兼容 IOS>11.2*/
	    padding-bottom: env(safe-area-inset-bottom);
	    background: linear-gradient(to bottom, #97e4db 0px, #a9e9e0 80px, #dcf7f5 160px, #eef5f4 240px, #f2f8f8 320px);
	    font-family: '微软雅黑';
	}

	button::after {
		display: none;
	}

	uni-scroll-view .uni-scroll-view::-webkit-scrollbar {
		display: none;
		width: 0 !important;
		height: 0 !important;
		-webkit-appearance: none;
		background: transparent;
		color: transparent;
	}

	.uni-tabbar .uni-tabbar__item {
		display: none;
	}

	.btn {
		height: 72rpx;
		line-height: 72rpx;
		box-sizing: border-box;
		display: flex;
		justify-content: center;
		align-items: center;
		margin: 0;
		font-size: 28rpx;
		border-radius: 10rpx;
		cursor: pointer;
		border: none !important;
	}
	.btn:active {
		opacity: 0.6;
	}
	.btn-default {
		background: #eee !important;
		color: #444 !important;
	}
	.btn-primary {
		background: #04BABE !important;
		color: #fff !important;
	}
	.btn-primary-plain {
		background: #d1f2f3 !important;
		color: #04BABE !important;
	}
	uni-checkbox:not([disabled]) .uni-checkbox-input:hover {
		border-color: #04BABE !important;
	}
	.uni-picker-container .uni-picker-action.uni-picker-action-confirm {
		color: #04BABE !important;
	}
</style>
